package com.shangma;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;

public class TestDem02 {
    public static void main(String[] args) {
        RestTemplate template = new RestTemplate();
        String path = "http://api.tianapi.com/networkhot/index?key=94aed0ea1c6e95f25086b8390ad26041";
        String phone = "faf";
        User user = new User();
        user.setName("wjt");
        user.setAge(18);
        //执行post请求
        ResponseEntity<String> stringResponseEntity = template.postForEntity(path, user, String.class);
        template.getForObject(path, String.class);


    }

    public static void method1() {
        //发送get请求,get,post默认发送的是json格式
        RestTemplate template = new RestTemplate();
        String path = "http://api.tianapi.com/networkhot/index?key=94aed0ea1c6e95f25086b8390ad26041";
        String forObject = template.getForObject(path, String.class);
        System.out.printf(forObject);
    }

    public static void method2() {
        RestTemplate template = new RestTemplate();
        String path = "http://api.tianapi.com/networkhot/index?key=94aed0ea1c6e95f25086b8390ad26041";
        ResponseEntity<String> forEntity = template.getForEntity(path, String.class);
    }

    //restFul风格
    public static void method3() {
        RestTemplate template = new RestTemplate();
        String path = "http://api.tianapi.com/networkhot/index?key=94aed0ea1c6e95f25086b8390ad26041/{0}";
        String phone = "faf";
        template.getForObject(path, String.class, phone);
    }
}
